<?php
namespace app\common\third;

use app\common\BaseLogic;

class Message extends BaseLogic
{
    protected $baseUrl = 'http://h5.hunlijia.com.cn/#';
    protected $customerAllocateQueue = 'customer_allocate_queue';
    
    public function buildCustomerMessage($fromUser, $toUser, $opts)
    {
        $url = $this->baseUrl . '/pages/customer/index/detail?id=' . $opts['id'];
        $content = "{$fromUser['realname']}给您分配了一条客资{$opts['contact']}\n点击查看<a href=\"{$url}\">详情</a>";
        // 添加到队列
        $this->redis->lpush($this->customerAllocateQueue, json_encode([
            'toUser' => $toUser,
            'content' => $content,
            'time'   => time(),
        ]));

        return $content;
    }

    // 发送导出成功消息
    public function buildExportSuccessMessage($user, $url)
    {
        $content = "您的导出任务已完成，点击<a href=\"{$url}\">下载</a>";
        
        return $content;
    }

    public function getCustomerAllocateQueue()
    {
        return $this->redis->lrange($this->customerAllocateQueue, 0, -1);
    }

    public function delCustomerAllocateQueue($value)
    {
        $this->redis->lrem($this->customerAllocateQueue, $value, 0);
    }
}